package edu.sctu.practice.class01.zhoumengxue.day20150924;


/**
 * Created by ASUS on 2015/9/24.
 */
public class CalculatorCounter {

    public void Check(String number1, String number2, String string) {
        double n1, n2, n3;
        if ((number1 != null && number2 != null) || (number1 != "" && number2 != "")) {
            n1 = Double.parseDouble(number1);
            n2 = Double.parseDouble(number2);
            n3 = counter(n1, n2, string);
            System.out.print(number1);
            System.out.print(string);
            System.out.print(number2);
            System.out.println("=" + n3);
        }
    }

    public double counter(double num1, double num2, String string) {

        if (string.equals("+")) {
            return num1 + num2;

        } else if (string.equals("-")) {
            return num1 - num2;

        } else if (string.equals("*")) {
            return num1 * num2;

        } else if (string.equals("/")) {

            if (num2 == 0) {
                System.out.print("0������Ϊ������");
                return -1;

            }
            return num1 / num2;
        } else {
            System.out.print("������Ϊ�������");
            return -1;
        }
    }

}
